package com.cakemallproject.controller;

import com.cakemallproject.pojo.Result;
import com.cakemallproject.pojo.mapperObj.OrderItem;
import com.cakemallproject.service.OrderItemService;
import com.cakemallproject.service.OrdersService;
import com.cakemallproject.service.impl.OrdersServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/orderItem")
public class OrderItemController {
    @Autowired
    private OrderItemService orderItemService;
    @Autowired
    private OrdersService ordersService;

    @GetMapping
    public Result list() {
        log.info("获取未被删除订单的详情列表");
        List<OrderItem> list = orderItemService.list();
        //过滤掉已被删除订单的详情
        List<Integer> oidList = ordersService.getOidByStatus(OrdersService.Order_isDelete);
        List<OrderItem> deletelist = new ArrayList<>();
        for (OrderItem orderItem : list) {
            if (oidList.contains(orderItem.getOid())) {
                deletelist.add(orderItem);
            }
        }
        for (OrderItem orderItem : deletelist) {
            list.remove(orderItem);
        }
        return Result.success(list);
    }
}
